"use strict";
!function (n) {
    var i = function (i, e) {
        function c(step) {
            r.config.current = (r.config.current < l.length-1) ? r.config.current + step : 0;
            o.stop(!1,!0).animate({
                left:-(r.config.current * r.config.w)+"px"
            },r.config.speed,function(){
                v(r.config.current);
            })
        }

        function t() {
            clearInterval(w), w = setInterval(function(){c(1)}, r.config.intervalTime)
        }

        var r = this;
        this.el = i, this.userConfig = e, this.config = {
            w: this.el.width(),
            current: 0,
            speed: 500,
            intervalTime: 5e3
        }, null != e && n.extend(this.config, this.userConfig);
        var f = this.el.children(".slider-img"), o = f.children("ul"), l = o.children("li");
        this.el.append('<a href="javascript:" class="slider-btn slider-btn-left">&lt;</a>'), this.el.append('<a href="javascript:" class="slider-btn slider-btn-right">&gt;</a>');
        var s = this.el.children(".slider-btn-left"), g = this.el.children(".slider-btn-right");
        this.el.append('<div class="slider-dot"><ul></ul></div>');
        for (var a = this.el.children(".slider-dot"), u = a.children("ul"), d = l.length, h = 0; h < d; h++)h === this.config.current ? u.append('<li class="active"></li>') : u.append("<li></li>");
        var p = u.children("li");
        o.css("left", -this.config.w * this.config.current - this.config.w);
        var v = function (n) {
            p.removeClass("active"), p.eq(n).addClass("active")
        };
        $.each(l,function(idx,liItem){
            $(liItem).width(r.config.w);
            $(liItem).find("img").width(r.config.w);
        })
        g.on("click", function (n) {
            t();

            c(1);
        }), s.on("click", function (n) {
            t();
           c(-1);
        }), p.on("click", function (i) {
            i.preventDefault(), t();
            var e = n(this).index();
            v(e);
            c(e- r.config.current);

        });
        var w = setInterval(function(){c(1)},r.config.intervalTime)
    };
    n.fn.extend({
        xSlider: function () {
            new i(n(this))
        }
    })
}(jQuery);
